package com.rzz.overalldemo.execption;

import org.springframework.http.HttpStatus;

import java.util.function.Supplier;

/**
 * @description:
 * @author: ruanzhizhi
 * @date: 2021/7/15 17:04
 */
public class ServiceException extends RuntimeException{
    private Integer code = HttpStatus.BAD_REQUEST.value();

    private String msg;

    public ServiceException() {
    }

    public ServiceException(String message) {
        super(message);
    }

    public ServiceException(int code, String message) {
        super(message);
        this.msg = message;
        this.code = code;
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }

    public static Supplier<ServiceException> of(String message) {
        return of(HttpStatus.BAD_REQUEST.value(), message);
    }

    public static Supplier<ServiceException> of(int code, String message) {
        return () -> new ServiceException(code, message);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
